package com.sky.runtime;

/**
 * @author : wushikai
 * <p>
 * date : 2022-05-07
 */
public class MemoryMonitor {


    public static void main(String[] args){
        Runtime run = Runtime.getRuntime();	//通过Runtime类的静态方法获取Runtime类的实例
        System.out.println("JVM最大内存量："+run.maxMemory());
        System.out.println("JVM空闲内存量："+run.freeMemory());
        String str = "Hello"+"World";
        System.out.println(str);
        for(int i=0;i<2000;i++){
            str = str + i;
        }
        System.out.println("JVM空闲内存量："+run.freeMemory());
        run.gc();
        System.out.println("垃圾回收之后的JVM空闲内存量："+run.freeMemory());
    }


}
